﻿(function () {
    var myApp = angular.module('MyControllers');

    // 正式或模拟考试计划控制器
    myApp.controller('processController', ['$scope', '$http', '$modal', 'processService', 'utils', function ($scope, $http, $modal, service, utils) {
        $scope.getList = function () {
            service.getList($scope.planType).success(function (data) {
                $scope.list = data;
            });
        };

        $scope.official = function () {
            $scope.planType = 0;
            $scope.getList();
        };

        $scope.imatate = function () {
            $scope.planType = 1;
            $scope.getList();
        };

        $scope.remove = function (model) {
            $modal.open({
                templateUrl: '/App/views/Process/Remove.html',
                controller: 'remove',
                backdrop: 'static',
                keyboard: false,
                resolve: {
                    params: function () {
                        return model;
                    }
                }
            });
        }

        $scope.$root.$on('reload', function () {
            $scope.getList();
        });

        $scope.official();
    }]);

    // 删除需要的控制器及方法列表
    myApp.controller('remove', ['$scope', '$routeParams', '$modalInstance', 'processService', 'utils', 'params', '$filter', function ($scope, $routeParams, $modalInstance, service, utils, params, $filter) {
        var model = params;

        $scope.planName = model.examPlanName;

        var methods = {
            save: function () {
                $scope.loadingState = true;

                var interval = window.setInterval(function () {
                    utils.notify('后台正在处理删除考试计划...', 'success');
                }, 5000);

                service.remove(model.examPlanInfoID).success(function (data) {
                    $scope.loadingState = false;
                    window.clearInterval(interval);

                    if (data.resultType == 'Success') {

                        $scope.close();
                        $scope.$emit('reload');
                        utils.notify('删除计划成功！', 'success');
                        window.location.reload();
                    } else {
                        utils.notify(data.message, 'warning');
                    }
                });
            },
            close: function () {
                $modalInstance.close(true);
            }
        };
        angular.extend($scope, methods);
    }]);
})();